package auth

import (
	"gitee.com/micro-plat/sas/sas/modules/auth"
	"gitee.com/micro-plat/sas/sas/modules/auth/conf"

	"github.com/micro-plat/hydra"
)

//MultiHandler .
type MultiHandler struct {
	aLib auth.IAuth
}

//NewMultiHandler .
func NewMultiHandler() (u *MultiHandler) {
	return &MultiHandler{
		aLib: auth.NewAuth(),
	}
}

// Handle .
func (o *MultiHandler) Handle(ctx hydra.IContext) (r interface{}) {
	ctx.Log().Debug("------多元签名认证------")
	ctx.Log().Debug("1.获取认证配置及请求参数")
	conf, params, err := conf.GetParams(ctx.Request().GetMap())
	if err != nil {
		return err
	}

	ctx.Log().Debug("2.签名认证、参数解密")
	gParam := ctx.Request().Path().Params()
	data, err := o.aLib.MultiAuth(params, conf, gParam.GetString("type1"), gParam.GetString("type2"))
	if err != nil {
		return err
	}

	ctx.Log().Debug("3.返回结果", data)
	return data
}
